package com.library.service;

import com.library.dao.UserRepository;
import com.library.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RegisterService {
    @Autowired
    private UserRepository userRepository;

    public User register(User user) {
        if (user.getUserName() == null || user.getUserName().equals("") || user.getPassword() == null || user.getPassword().equals("") || user.getEmail() == null || user.getEmail().equals("") || user.getFullName() == null || user.getPhoneNo() == null || user.getPhoneNo().equals("")) {
            return null;
        }
        if(userRepository.findByName(user.getUserName())!=null){
            return null;
        }
        userRepository.addUser(user);
        return userRepository.findByName(user.getUserName());
    }
}
